{extend name="public/base" /}

{block name="title"}<title>{if condition="$data"}{$Think.lang.edit}{else /}{$Think.lang.create}{/if}</title>{/block}

{block name="pjax_container"}
<section class="content-header">
    <h1>网站导航信息</h1>
    <ol class="breadcrumb">
        <li class="active"><i class="fa fa-dashboard"></i> 添加网站导航</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal" method="POST" action="" onsubmit="return false" >
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab1" data-toggle="tab">添加导航</a></li>
                        <li class="pull-right">
                        	<a href="javascript:history.back(-1)" class="btn btn-sm" style="padding:10px 2px;"><i class="fa fa-list"></i>
                        		 {$Think.lang.back}
                        	</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab1">
                            <input type="hidden" name="id" value="{$data.id}" />
                            <div class="form-group">
                                <label class="col-sm-2 control-label">导航分类</label>
                                <div class="col-sm-7">
                                    <select class="form-control lb_type" id="type_val" name="type" style="width:100%;">
                                    	<option value="" >请选择</option>
                                    	{volist name="fenlei" id="vo" key="k"}
                                        	<option value="{$k}" {if condition="$data.type eq $k "}selected="selected"{/if} >{$vo}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">父级导航</label>
                                <div class="col-sm-7">
                                    <select class="select2 form-control lb_type" id="pid_val" data-type="666" name="pid" style="width:100%;">
                                    	<option value="0" >顶级导航</option>
										{volist name="list" id="vv"}
											<option value="{$vv.id}" {if condition="$data.pid eq $vv.id "}selected="selected"{/if} {if condition="$vv.h_layer egt 2"} disabled{/if} >
												{for start="1" end="$vv['h_layer']"}├──{/for}{$vv.name}
											</option>
										{/volist}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">导航名称</label>
                                <div class="col-sm-7">
                                	<input class="form-control" name="name" value="{$data.name}" placeholder="导航名称">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">导航别名</label>
                                <div class="col-sm-7">
                                	<input class="form-control" name="title" value="{$data.title}" placeholder="导航别名,只能用英文字符">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">导航URL</label>
                                <div class="col-sm-7">
                                	<input class="form-control" name="url" value="{$data.url}" placeholder="导航url">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">icon图标</label>
                                <div class="col-sm-7">
                                	<div class="input-group input-group-sm">
	                                	<input class="form-control iconinput" name="icon" value="{$data.icon}" placeholder="icon图标,例如:fa-user">
	                                	<span class="input-group-btn">
						                  	<button type="button" class="btn btn-warning btn-info btn-flat" id="icon_btn" data-toggle="modal" data-target="#iconkuang">图标列表</button>
						                </span>
						            </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">图标颜色</label>
                                <div class="col-sm-7">
                                	<input class="form-control" name="iconcolor" value="{$data.iconcolor}" placeholder="导航按钮背景颜色,例如:#3B9B15">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">是否显示</label>
                                <div class="col-sm-7">
                                    <select class="form-control lb_type" name="closed" style="width:100%;">
                                        <option value="1" {if condition="$data.closed eq 1 "}selected="selected"{/if} >显示</option>
                                        <option value="0" {if condition="$data.closed eq 0 "}selected="selected"{/if} >隐藏</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">是否新窗口打开</label>
                                <div class="col-sm-7">
                                    <select class="form-control lb_type" name="target" style="width:100%;">
                                        <option value="0" {if condition="$data.target eq 0 "}selected="selected"{/if} >当前窗口</option>
                                        <option value="1" {if condition="$data.target eq 1 "}selected="selected"{/if} >新窗口</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">角标信息数量</label>
                                <div class="col-sm-7">
                                	<input class="form-control" name="news" value="{$data.news|default='0'}" placeholder="显示角标信息数量">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">角标背景颜色</label>
                                <div class="col-sm-7">
                                	<input class="form-control" name="bgcolor" value="{$data.bgcolor}" placeholder="角标背景颜色,例如:bg-green">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">排序</label>
                                <div class="col-sm-7">
                                	<input class="form-control" name="orderby" value="{$data.orderby|default='100'}" placeholder="排序">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <div class="col-sm-2"></div>
                        <div class="col-sm-7">
                            <div class="btn-group pull-right">
                                <button type="submit" class="btn btn-info pull-right submits" data-loading-text="&lt;i class='fa fa-spinner fa-spin '&gt;&lt;/i&gt; {$Think.lang.submit}">{$Think.lang.submit}</button>
                            </div>
                            <div class="btn-group pull-left">
                                <button type="reset" class="btn btn-warning">{$Think.lang.reset}</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</section>
<script type="text/javascript">
$(function(){
    /*ajax页面加载icheck，有该控件的页面才需要*/
    $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
        checkboxClass: 'icheckbox_minimal-blue',
        radioClass: 'iradio_minimal-blue'
    });

//  /*ajax页面加载icheck，有该控件的页面才需要*/
    $(".select2").select2({language:"zh-CN"});

    {if condition=" $rest_login == 1 "}
    	restlogin('{$rest_login_info}');   //登录超时
    {/if}
    if( $('#iconkuang').length == 0  ){
    	my_iconlist();//加载icon图标列表
		$('#icon_list').on('click','.thisicon',function(){
			var names = $(this).attr('data-iconname');
			$('.iconinput').val(names);
			$('#iconkuang').modal('hide');//关闭弹窗
		})
    }

	$("#type_val").change(function(){
		var type_val = $(this).val();
		$.ajax({
		    url: "{:url('index')}", //请求url
		    type: "post",  //请求的类型
		    dataType: "json",  //数据类型
		    data: {type:type_val}, //发送到服务器的数据
		    success:function(data) { //成功后执行
		    	var html = '<option value="0" >顶级导航</option>';
				if( data.data != null){
			    	for (var i = 0; i < data.data.length; i++) {
			    		var eJi = '', JingYong = '';
			    		for(var u = 1; u < data.data[i].h_layer; u++ ){
			    			eJi += '├──';
			    		}
			    		if( data.data[i].h_layer >= 2 ){
			    			JingYong = ' disabled';
			    		}
			    		html += '<option value="'+ data.data[i].id +  '" ' + JingYong +' >' + eJi +
			    		data.data[i].name + '</option>';
			    	}
				}
				$('#pid_val').html(html);
		    },
		    error:function(data) { //失败后执行
		        console.log(data);
		    }
		});
	});




})
</script>
{/block}